ASP.NET 5 C#

Generate Context and Entity Classes from an Existing Database

Active Server Pages

ASP Web Forms was released in 2003 (based on the Windows Server and the .NET Framework)

ASP.NET Model-View-Controller 5 was released in 2009 (based on Windows Server and .NET Framework and Supported in Visual Studio 2019)

ASP.NET Core Model-View-Controller was released in 2017 (based on cross platform .NET Core and Supported in Visual Studio 2022)

I used Visual Studio 2019 and ASP.NET MVC 5 to create a todo app.

I created a new project

I configured the new project

I created a Model-View-Controller web application

I ran the template project (notice the "ASP.NET MVC gives" text in the index.cshtml file and the web browser).

The _Layout.cshtml file provides a common web page framework and navigation

Web requests are handled by Controller functions/methods. The controller function will typically return a view (the Web response). The About function sets a "Message" value and then returns a corresponding About view.

Notice that the About view renders the "Message".

I added a view page to the HelloWorld folder.

I named the new page "Index" making it the home page for the new folder.

I selected the existing _Layout page

I added a reference to a "Name" value.

I added a new controller to the project

I created an empty controller.

I named the controller HelloWorldController (in line with the folder I had already created)

I added the folder name HelloWorld to the url and got the result above

I updated the Controller function to set the "Name" value before returning the view. I refreshed the browser.

I selected the Models folder and selected the Add | New Item... menu item

I entered the name ToDoContext and selected ADO.NET Entity Data Model

I selected Code First from database

New data connection

Test connection succeeded

I asked Visual Studio to save the connection details in the Web.Config file (notice that the Web.Config file is never returned to a client browser)

I selected the Tasks table

The Task class is generated

I selected the Controller folder and selected the Add | New Scaffolded Item... menu item

I selected the MVC 5 Controller with view, using Entity Framework option

I entered the Model class name (Task) and the Data context class (ToDoContext).

Visual Studio added CRUD controller functions and views (Visual Studio was confused by class "Task").

The controller functions includes Index. The TaskController.Index function will fetch all Tasks from the database and then display then using the corresponding Tasks/Index view (Models.Task class name fully qualified to avoid confusion).

The TaskController.Index function is executed when a user navigates to /Tasks (see above)